﻿using DC2010.Objects.Base;
using DC2010.Objects.Data;

namespace DC2010.Effects.AI
{
    public class P_MoveMonsterPartyRandom_Effect : EffectLogic
    {
        public int counter;
        public int speed;
        public override bool CheckPumpCondition(BaseObject aTarget)
        {
            //return true;
            counter++;
            return (counter % speed) == 0;
        }

        public P_MoveMonsterPartyRandom_Effect(EffectData ed)
            : base(ed)
        {
            ShortName = "Move party";
            LongName = "Effect moves party in allowed dirrections.";
            EffectType = EffectType.Pump;

        }

        public override void Pump(BaseObject aTarget)
        {
            //int speed = Data.Params.Find(A => A.Key == "SPEED").Value.ToInt();

            //if (aTarget is PartyData)
            //{
            //    DateTime dtStart = DateTime.Now;

            //    PartyData p = (PartyData)aTarget;
            //    if (p.Location==null)
            //    {
            //        Tile t = p.FindOwner();
            //        p.Info.Loc = new DungeonLoc();
            //        if (t != null)
            //        {
            //            p.Info.Loc.X = t.Info.Loc.X;
            //            p.Info.Loc.Y = t.Info.Loc.Y;
            //            p.Info.Loc.Floor = t.Info.Loc.Floor;
            //        }
            //    }

            //    if (p != null)
            //    {
            //        int X = p.Info.Loc.X;
            //        int Y = p.Info.Loc.Y;

            //        int newX = X;
            //        int newY = Y;

            //        Map m = Root.I.IS.GetMap(p.Info.Loc.Floor);

            //        if (m != null)
            //        {
            //            Tile tUp = m.GetTile(X, Y - 1);
            //            Tile tDown = m.GetTile(X, Y + 1);
            //            Tile tRight = m.GetTile(X + 1, Y);
            //            Tile tLeft = m.GetTile(X - 1, Y);

            //            List<Point> possibleTiles = new List<Point>();

            //            if (CanIMoveHere(tUp)) possibleTiles.Add(new Point(X, Y - 1));
            //            if (CanIMoveHere(tDown)) possibleTiles.Add(new Point(X, Y + 1));
            //            if (CanIMoveHere(tLeft)) possibleTiles.Add(new Point(X - 1, Y));
            //            if (CanIMoveHere(tRight)) possibleTiles.Add(new Point(X + 1, Y));

            //            Random r = new Random();
            //            int iResult = r.Next(possibleTiles.Count);

            //            if (possibleTiles.Count > 0)
            //            {
            //                Point pt = possibleTiles[iResult];
            //                p.MoveParty(p.Info.Loc.Floor, pt.X, pt.Y, p.Info.Loc.Facing);
            //            }
            //        }
            //    }

            //    if ((DateTime.Now - dtStart).TotalSeconds>0)
            //        log.Debug("P_MoveMonsterPartyRandom_Effect::Pump(" + aTarget + ") takes: " + (DateTime.Now - dtStart).TotalSeconds + " seconds");

            //}
        }

        public bool CanIMoveHere(TileData t)
        {
            return true;//!t.IsWall;
        }
    }
}
